/**
 * 
 */
package com.ssl.mall.common.bean;

import java.util.HashMap;
import java.util.Map;

import com.ssl.mall.common.exception.ErrorCode;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * rest 接口统一响应模版
 * 
 * @author
 * @date 2021年4月25日 上午10:38:27
 * @version 1.0
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class Result extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public Result() {
		put("code", ErrorCode.OK_CODE);
		put("message", ErrorCode.OK_MESSAGE);
	}

	// ------------------------- 异常输出 -----------------------------
	public static Result error() {
		return error(ErrorCode.UNKNOWN_ERROR_CODE, ErrorCode.UNKNOWN_ERROR_CODE);
	}

	public static Result error(String msg) {
		return error(ErrorCode.UNKNOWN_ERROR_CODE, msg);
	}

	public static Result error(String code, String msg) {
		Result result = new Result();
		result.put("code", code);
		result.put("message", msg);
		return result;
	}

	// ------------------------- 成功输出 -----------------------------
	public static Result ok() {
		return new Result();
	}

	public static Result ok(String msg) {
		Result result = new Result();
		result.put("msg", msg);
		return result;
	}

	public static Result ok(Map<String, Object> data) {
		Result result = new Result();
		result.putAll(data);
		return result;
	}

	@Override
	public Result put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
